namespace System.Xml.Serialization.Internal
{
    internal sealed class GuidRuntimeSerializer : XmlRuntimeSerializer<Guid>
    {
        private GuidRuntimeSerializer() { }
        private static GuidRuntimeSerializer _instance = new GuidRuntimeSerializer();
        public static GuidRuntimeSerializer Instance { get { return _instance; } }
        protected override Guid Read(IXmlPropertyReader reader, string propertyName)
        {
            return Guid.Deserialize(reader, propertyName);
        }
        protected override void Write(Guid value, IXmlPropertyWriter writer, string propertyName)
        {
            Guid.Serialize(writer, propertyName, value);
        }
    }
    internal sealed class BooleanRuntimeSerializer : XmlRuntimeSerializer<bool>
    {
        private BooleanRuntimeSerializer() { }
        private static BooleanRuntimeSerializer _instance = new BooleanRuntimeSerializer();
        public static BooleanRuntimeSerializer Instance { get { return _instance; } }
        protected override bool Read(IXmlPropertyReader reader, string propertyName)
        {
            return Boolean.Deserialize(reader, propertyName);
        }
        protected override void Write(Boolean value, IXmlPropertyWriter writer, string propertyName)
        {
            Boolean.Serialize(writer, propertyName, value);
        }
    }
    internal sealed class ByteRuntimeSerializer : XmlRuntimeSerializer<byte>
    {
        private ByteRuntimeSerializer() { }
        private static ByteRuntimeSerializer _instance = new ByteRuntimeSerializer();
        public static ByteRuntimeSerializer Instance { get { return _instance; } }
        protected override Byte Read(IXmlPropertyReader reader, string propertyName)
        {
            return Byte.Deserialize(reader, propertyName);
        }
        protected override void Write(byte value, IXmlPropertyWriter writer, string propertyName)
        {
            Byte.Serialize(writer, propertyName, value);
        }
    }
    internal sealed class SByteRuntimeSerializer : XmlRuntimeSerializer<SByte>
    {
        private SByteRuntimeSerializer() { }
        private static SByteRuntimeSerializer _instance = new SByteRuntimeSerializer();
        public static SByteRuntimeSerializer Instance { get { return _instance; } }
        protected override SByte Read(IXmlPropertyReader reader, string propertyName)
        {
            return SByte.Deserialize(reader, propertyName);
        }
        protected override void Write(SByte value, IXmlPropertyWriter writer, string propertyName)
        {
            SByte.Serialize(writer, propertyName, value);
        }
    }
    internal sealed class Int16RuntimeSerializer : XmlRuntimeSerializer<Int16>
    {
        private Int16RuntimeSerializer() { }
        private static Int16RuntimeSerializer _instance = new Int16RuntimeSerializer();
        public static Int16RuntimeSerializer Instance { get { return _instance; } }
        protected override Int16 Read(IXmlPropertyReader reader, string propertyName)
        {
            return Int16.Deserialize(reader, propertyName);
        }
        protected override void Write(Int16 value, IXmlPropertyWriter writer, string propertyName)
        {
            Int16.Serialize(writer, propertyName, value);
        }
    }
    internal sealed class Int32RuntimeSerializer : XmlRuntimeSerializer<int>
    {
        private Int32RuntimeSerializer() { }
        private static Int32RuntimeSerializer _instance = new Int32RuntimeSerializer();
        public static Int32RuntimeSerializer Instance { get { return _instance; } }
        protected override int Read(IXmlPropertyReader reader, string propertyName)
        {
            return Int32.Deserialize(reader, propertyName);
        }
        protected override void Write(Int32 value, IXmlPropertyWriter writer, string propertyName)
        {
            Int32.Serialize(writer, propertyName, value);
        }
    }
    internal sealed class Int64RuntimeSerializer : XmlRuntimeSerializer<Int64>
    {
        private Int64RuntimeSerializer() { }
        private static Int64RuntimeSerializer _instance = new Int64RuntimeSerializer();
        public static Int64RuntimeSerializer Instance { get { return _instance; } }
        protected override Int64 Read(IXmlPropertyReader reader, string propertyName)
        {
            return Int64.Deserialize(reader, propertyName);
        }
        protected override void Write(Int64 value, IXmlPropertyWriter writer, string propertyName)
        {
            Int64.Serialize(writer, propertyName, value);
        }
    }
    internal sealed class UInt16RuntimeSerializer : XmlRuntimeSerializer<UInt16>
    {
        private UInt16RuntimeSerializer() { }
        private static UInt16RuntimeSerializer _instance = new UInt16RuntimeSerializer();
        public static UInt16RuntimeSerializer Instance { get { return _instance; } }
        protected override UInt16 Read(IXmlPropertyReader reader, string propertyName)
        {
            return UInt16.Deserialize(reader, propertyName);
        }
        protected override void Write(UInt16 value, IXmlPropertyWriter writer, string propertyName)
        {
            UInt16.Serialize(writer, propertyName, value);
        }
    }
    internal sealed class UInt32RuntimeSerializer : XmlRuntimeSerializer<UInt32>
    {
        private UInt32RuntimeSerializer() { }
        private static UInt32RuntimeSerializer _instance = new UInt32RuntimeSerializer();
        public static UInt32RuntimeSerializer Instance { get { return _instance; } }
        protected override UInt32 Read(IXmlPropertyReader reader, string propertyName)
        {
            return UInt32.Deserialize(reader, propertyName);
        }
        protected override void Write(UInt32 value, IXmlPropertyWriter writer, string propertyName)
        {
            UInt32.Serialize(writer, propertyName, value);
        }
    }
    internal sealed class UInt64RuntimeSerializer : XmlRuntimeSerializer<ulong>
    {
        private UInt64RuntimeSerializer() { }
        private static UInt64RuntimeSerializer _instance = new UInt64RuntimeSerializer();
        public static UInt64RuntimeSerializer Instance { get { return _instance; } }
        protected override ulong Read(IXmlPropertyReader reader, string propertyName)
        {
            return UInt64.Deserialize(reader, propertyName);
        }
        protected override void Write(ulong value, IXmlPropertyWriter writer, string propertyName)
        {
            UInt64.Serialize(writer, propertyName, value);
        }
    }
    internal sealed class FloatRuntimeSerializer : XmlRuntimeSerializer<float>
    {
        private FloatRuntimeSerializer() { }
        private static FloatRuntimeSerializer _instance = new FloatRuntimeSerializer();
        public static FloatRuntimeSerializer Instance { get { return _instance; } }
        protected override float Read(IXmlPropertyReader reader, string propertyName)
        {
            return Float.Deserialize(reader, propertyName);
        }
        protected override void Write(float value, IXmlPropertyWriter writer, string propertyName)
        {
            Float.Serialize(writer, propertyName, value);
        }
    }
    internal sealed class DoubleRuntimeSerializer : XmlRuntimeSerializer<double>
    {
        private DoubleRuntimeSerializer() { }
        private static DoubleRuntimeSerializer _instance = new DoubleRuntimeSerializer();
        public static DoubleRuntimeSerializer Instance { get { return _instance; } }
        protected override double Read(IXmlPropertyReader reader, string propertyName)
        {
            return Double.Deserialize(reader, propertyName);
        }
        protected override void Write(Double value, IXmlPropertyWriter writer, string propertyName)
        {
            Double.Serialize(writer, propertyName, value);
        }
    }
    internal sealed class DecimalRuntimeSerializer : XmlRuntimeSerializer<decimal>
    {
        private DecimalRuntimeSerializer() { }
        private static DecimalRuntimeSerializer _instance = new DecimalRuntimeSerializer();
        public static DecimalRuntimeSerializer Instance { get { return _instance; } }
        protected override decimal Read(IXmlPropertyReader reader, string propertyName)
        {
            return Decimal.Deserialize(reader, propertyName);
        }
        protected override void Write(Decimal value, IXmlPropertyWriter writer, string propertyName)
        {
            Decimal.Serialize(writer, propertyName, value);
        }
    }
    internal sealed class AttributeRuntimeSerializer : XmlRuntimeSerializer<string>
    {
        private string _attributeName;
        private AttributeRuntimeSerializer() { }
        public AttributeRuntimeSerializer(string attributeName)
        {
            _attributeName = attributeName;
        }
        private static AttributeRuntimeSerializer _instance = new AttributeRuntimeSerializer();
        public static AttributeRuntimeSerializer Instance { get { return _instance; } }
        protected override string Read(IXmlPropertyReader reader, string propertyName)
        {
            if (_attributeName == null)
            {
                return reader.ReadAttributes[propertyName];
            }
            return reader.ReadAttributes[_attributeName];
        }
        protected override void Write(string value, IXmlPropertyWriter writer, string propertyName)
        {
            if (_attributeName == null)
            {
                writer.WriteAttributes[propertyName] = value;
                return;
            }
            writer.WriteAttributes[_attributeName] = value;
        }
    }
    internal sealed class ElementRuntimeSerializer : XmlRuntimeSerializer
    {
        private string _elementName;
        private ElementRuntimeSerializer()
        {
        }
        public ElementRuntimeSerializer(string elementName)
        {
            _elementName = elementName;
        }
        public ElementRuntimeSerializer(string elementName, Type type)
        {
            _elementName = elementName;
            InitializeRuntimeType(type);
        }
        private static ElementRuntimeSerializer _instance = new ElementRuntimeSerializer();
        public static ElementRuntimeSerializer Instance { get { return _instance; } }
        public override void Serialize(object value, IXmlPropertyWriter writer, string propertyName)
        {
            if (_elementName == null)
            {
                writer.Write(propertyName, Serialize(value));
                return;
            }
            writer.Write(_elementName, Serialize(value));
        }
        public override object Deserialize(IXmlPropertyReader reader, string propertyName)
        {
            if (_elementName == null)
            {
                return Deserialize(reader.Read(propertyName));
            }
            return Deserialize(reader.Read(_elementName));
        }
    }
    internal sealed class StringRuntimeSerializer : XmlRuntimeSerializer<string>
    {
        private StringRuntimeSerializer() { }
        private static StringRuntimeSerializer _instance = new StringRuntimeSerializer();
        public static StringRuntimeSerializer Instance { get { return _instance; } }
        protected override string Read(IXmlPropertyReader reader, string propertyName)
        {
            return String.Deserialize(reader, propertyName);
        }
        protected override void Write(String value, IXmlPropertyWriter writer, string propertyName)
        {
            String.Serialize(writer, propertyName, value);
        }
    }
    internal sealed class EnumRuntimeSerializer : XmlRuntimeSerializer<object>
    {
        private EnumRuntimeSerializer() { }
        private static EnumRuntimeSerializer _instance = new EnumRuntimeSerializer();
        public static EnumRuntimeSerializer Instance { get { return _instance; } }
        protected override object Read(IXmlPropertyReader reader, string propertyName)
        {
            return Enum.Deserialize(reader, propertyName);
        }
        protected override void Write(object value, IXmlPropertyWriter writer, string propertyName)
        {
            Enum.Serialize(writer, propertyName, value);
        }
    }
}
